package com.zhuss.advice.processor;

import com.zhuss.advice.db.dao.ext.ComplaintDao;
import com.zhuss.advice.db.dao.ext.ComplaintSonDao;
import com.zhuss.advice.db.entity.Complaint;
import com.zhuss.advice.db.entity.ComplaintSon;
import com.zhuss.bean.bo.advice.Complaint.AssignedComplaintBo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.ComplaintType;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author: zhushanshuo
 * @Date: 2020/4/13 15:27
 */
@Component("complaintAssigned")
public class ComplaintAssigned extends AbstractProcessor<Object, AssignedComplaintBo> implements Processor<Object, AssignedComplaintBo> {

    @Autowired
    private ComplaintDao complaintDao;

    @Autowired
    private ComplaintSonDao complaintSonDao;

    @Override
    public void check(AssignedComplaintBo assignedComplaintBo) throws WpsException {

    }

    @Override
    public Object process(AssignedComplaintBo bo) throws WpsException {
        ComplaintSon son = new ComplaintSon();
        son.setComplaintId(bo.getComplaintId());
        son.setType(ComplaintType.已交办.key());
        son.setSonContent(bo.getContent());
        son.setArea(bo.getConcurrentArea());

        son.setCreator(bo.getConcurrentUserName());
        son.setCreatorId(bo.getConcurrentUserId());
        son.setCreateTime(new Date());
        complaintSonDao.create(son);

        Complaint c = new Complaint();
        c.setComplaintId(bo.getComplaintId());
        c.setStatus(ComplaintType.已交办.key());
        c.setDealTime(bo.getAssignedTime());
        c.setCompany(bo.getCompanyId());
        c.setPeople(bo.getPerson());
        complaintDao.updateByPrimaryKeySelective(c);
        return null;
    }

    @Override
    public Object log(AssignedComplaintBo param) throws WpsException {
        OpLog record = new OpLog();
        record.setMoudle(MoudleEnum.意见建议.key());
        record.setAction(LogActionEnum.投诉交办.key());
        record.setTargetId(param.getComplaintId());
        record.setTargetName(param.getComplaintNo());
        record.setContent("参数: " + JsonUtil.toJson(param));
        record.setReason(param.getExceptionReason());

        record.setCreatorId(param.getConcurrentUserId());
        record.setCreator(param.getConcurrentUserName());
        record.setCreateTime(new Date());
        log(record);
        return null;
    }
}
